package com.feidee.fd.sml.algorithm.ml

import com.feidee.fd.sml.algorithm.component.ml.classification.{LRComponent, LogisticRegressionParam}
import com.feidee.fd.sml.algorithm.util.{TestingDataGenerator, ToolClass}
import org.scalatest.FunSuite

/**
  * @Author: dongguosheng
  * @Date: 2018/8/24 13:40
  */
class LRComponentSuite extends FunSuite {
  val paramStr: String =
    """
      |{
      |	'input_pt': 'a',
      |	'output_pt': 'a',
      |	'featuresCol': 'features',
      |	'labelCol': 'label',
      | 'probabilityCol': 'probability',
      |	'maxDepth': 5,
      |	'modelPath': '',
      | 'metrics': ['accuracy', 'auc', 'pr', 'abc']
      |}
    """.stripMargin
  val lr = new LRComponent
  val param: LogisticRegressionParam = lr.parseParam(new ToolClass().encrypt(paramStr))

  /**
    * LogisticRegress 参数构造方法测试：检测到读取出合法参数 & 成功赋值默认参数，即认为测试通过
    */
  test("LogisticRegress parameter construction test") {
    assert("a".equals(param.input_pt) & "a".equals(param.output_pt) & "features".equals(param.featuresCol) &
      "label".equals(param.labelCol) & "rawPrediction".equals(param.rawPredictionCol) & "prediction".equals(param.predictionCol) &
      "probability".equals(param.probabilityCol) & "".equals(param.modelPath)
    )
  }

  /**
    * LogisticRegress 模型训练功能测试：传入生成的测试数据和正确参数，可以正常训练 LogisticRegress 模型，且预测结果列等于生成数据列数，即认为测试通过
    */
  test("LogisticRegress training function test") {
    // 测试模型训练方法
    param.verify()
    val testingData = TestingDataGenerator.makeOrderedTrainingData(5, 20)
    val newData = lr.process(param, testingData)
    testingData.show()
    newData.show()
    //    assert(result._1.numClasses == 2)
    //    assert(result._2.count() == 20)
  }
}
